<%@page import="com.AAL.Model.Account"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%
	Account myAccount = null;
	if(session.getAttribute("myAccount")!=null){
		myAccount = (Account) session.getAttribute("myAccount");
	}else {
		%>
		<jsp:forward page="index.jsp"></jsp:forward>
		<%
		
	}
	
%>

<h3 class='pageTitle' style="width: 100%;"><span>Lịch sử
thanh toán của đại lý</span></h3>
<s:form id="form" method="post" action="#" theme="simple"
	cssClass="yform">
	<div style="color:red;margin:10px 0px; margin-left:10%; font-weight: bold; font-size: 15px; "> <s:actionmessage/></div>
	
	<div class="type-text"><label for="echo">Từ ngày: <span style="color:gray; "> (mm/dd/yyyy)</span> </label> <sj:datepicker
		id="fromDate" name="fromDate" readonly="true" changeMonth="true"
		changeYear="true" cssClass="txtField smallInput wide" /> <label
		for="echo">Đến ngày:  <span style="color:gray; "> (mm/dd/yyyy)</span> </label> <sj:datepicker id="toDate" name="toDate"
		readonly="true" changeMonth="true" changeYear="true"
		cssClass="txtField smallInput wide" /></div>
	<div class="type-button" style="margin-left: 48%;"><s:url
		id="Dealer_searchingPayment" value="/Dealer_searchingPayment" /> <sj:submit
		title="Tìm kiếm" id="subDealer_searchingPayment" targets="container" indicator="indicator-ajax"
		href="%{Dealer_searchingPayment}" value="Hiển thị" button="true" />

	<s:url id="Dealer_paymentOfDealer" value="/Dealer_paymentOfDealer" />
	<sj:a title="Nhập lại" id="lnkDealer_paymentOfDealer_1"
		href="%{Dealer_paymentOfDealer}" targets="container" button="true">
				     Nhập lại
				    </sj:a></div>
</s:form>
<div style="margin: 10px;"><s:form id="form" method="post"
	action="#">
	<fieldset style="border: solid 1px black;"><legend
		style="margin-left: 10px; font-weight: bold;">Thông tin tài khoản</legend>
	<div class="type-text"><label for="echo">Số dư trong tài khoản: </label><label for="echo" style="margin-left: 5%;"><% if(myAccount.getDealer().getOutstanding().floatValue()<=0.0f){ out.print(Math.abs(myAccount.getDealer().getOutstanding().floatValue())); }else {out.print(0);} %> </label> <label
		for="echo">Số nợ hiện tại: </label><label for="echo"
		style="margin-left: 5%;"><% if(myAccount.getDealer().getOutstanding().floatValue()>0.0f){ out.print(Math.abs(myAccount.getDealer().getOutstanding().floatValue())); }else {out.print(0);} %> </label></div>
	</fieldset>
</s:form></div>
<div style="clear: both;"></div>

<div style="margin: 10px;"><s:if test="lstPaymentOfDealers==null">
Không có dữ liệu
</s:if> <s:if test="lstPaymentOfDealers!=null">
	<table width="95%" cellpadding="0" cellspacing="0" id="box-table-a"
		summary="Employee Pay Sheet">
		<thead>
			<tr>
				<th width="10%" scope="col">STT</th>
				<th width="30%" scope="col">Ngày thanh toán</th>
				<th width="30%" scope="col">Trước khi thanh toán</th>
				<th width="30%" scope="col">Số tiền thanh toán</th>

			</tr>
		</thead>
		<tbody>
			<% int stt=1; %>
			<s:iterator value="lstPaymentOfDealers">
				<tr>
					<td><%=stt++ %></td>
					<td><s:date name="paymentDate" format="dd/MM/yyyy"/></td>
					<td><s:property value="prePaymentMoney"/></td>
					<td><s:property value="paymentMoney"/></td>
				</tr>
			</s:iterator>

			<%					
				int totalPage =1;
				if(session.getAttribute("totalPageOfPayment")!=null){
					totalPage =(Integer) session.getAttribute("totalPageOfPayment");
				}
			%>
			<tr class="footer">
				<td colspan="1">&nbsp; </td>
				<td align="right">&nbsp;Tổng số trang: <%=totalPage %></td>
				<td colspan="2" align="right"><!--  PAGINATION START  -->
				<div class="pagination">
				
				<%
					if(totalPage>1){
						int startPage = 1;
						if(session.getAttribute("startPage")!=null)
							startPage = (Integer)session.getAttribute("startPage");							
						int totalCurrentPage = 5;
						if(totalCurrentPage>totalPage)
							totalCurrentPage=totalPage;
						// Hien thi Button Previous date
						%>												
							<s:if test="prePage==-1">
								<span class="previous-off">&laquo; Trước</span>
							</s:if>
							<s:if test="prePage!=-1">
							<s:url id="Dealer_pagingPayment" action="Dealer_pagingPayment" >
								<s:param name="p" value="prePage"></s:param>
							</s:url>
						    <sj:a href="%{Dealer_pagingPayment}" 
						      	targets="container" indicator="indicator"					    	
						    >
						   &laquo; Trước
						    </sj:a>	
							</s:if>
						<%		
						
						for(int i=0; i< totalCurrentPage; i++){
						session.setAttribute("p_i",i+startPage);
						String currentPage = request.getParameter("p");
						if(currentPage==null){
							currentPage="1";
						}
						if(currentPage!=null && currentPage.equals(Integer.toString(i+startPage))){
						%>  <span class="active"><%=i+startPage %></span>
						<%
						}else{
						%>						
							<s:url id="Dealer_pagingPayment" action="Dealer_pagingPayment" >
								<s:param name="p" value="#session.p_i"></s:param>
							</s:url>
						    <sj:a href="%{Dealer_pagingPayment}" 
						    	targets="container" indicator="indicator"					    	
						    >
						    <%=i+startPage %>
						    </sj:a>	
						
						<%									
							}
						}
						%>												
						<s:if test="nextPage==-1">
							<span class="next-off">&laquo; Sau</span>
						</s:if>
						<s:if test="nextPage!=-1">
						<s:url id="Dealer_pagingPayment" action="Dealer_pagingPayment" >
							<s:param name="p" value="nextPage"></s:param>
						</s:url>
					    <sj:a href="%{Dealer_pagingPayment}" 
					      	targets="container" indicator="indicator"					    	
					    >
					   &laquo; Sau
					    </sj:a>	
						</s:if>
					<%		
					}
				%>
				
				<!--<span class="previous-off">&laquo;
				Previous</span> <span class="active">1</span>
				<a href="#">2</a> 
				<a href="#">3</a>
				<a href="#">4</a>
				<a href="#">5</a>
				<a href="#" class="next">Next&raquo;</a>
				--></div>
				<!--  PAGINATION END  --></td>
			</tr>
		</tbody>
	</table>
</s:if></div>

